package cbbx_sm.clustering;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.List;

import org.junit.Test;

import cbbx_sm.endtoend.EndToEndTestUtils;
import cbbx_sm.parser.CameraData;
import cbbx_sm.probabilistic_model.Cluster;
import cbbx_sm.probabilistic_model.Clustering;
import cbbx_sm.utils.ExperimentManager;

public class ClusteringEqualSize {
	@Test public void testClustersSize() throws IOException {
		int k = 4;
		String FILE_NAME_FORMAT = "data/cameraData/manual/%s%s.txt";
		ExperimentManager.useManualDataFormat = true;
		ArrayList<String> cameraIds = new ArrayList<String>();
		cameraIds.add("18");
		String trainDay = "20090528";
		LinkedHashMap<String, CameraData> camDataMap = EndToEndTestUtils.loadCameraData(FILE_NAME_FORMAT, cameraIds, trainDay);
		
		// Each camera has a cluster.		
		Hashtable<String, List<Cluster>> camClusters = new Hashtable<String, List<Cluster>>();
		for (String cam: cameraIds){
			System.out.println("Clustering cam "+cam+"...");
			List<Cluster> clusters = Clustering.kMeansClustering(camDataMap.get(cam), k);
			Collections.sort(clusters, new Comparator<Cluster>(){

				@Override
				public int compare(Cluster arg0, Cluster arg1) {
					return Double.compare(arg0.getX(), arg1.getX());
				}
			});
			camClusters.put(cam, clusters);
			for (Cluster c: clusters) {
				System.out.println(c);
			}
		}
	}

}
